package com.dormitory123.millet.dao.Impl;

import com.dormitory123.millet.dao.BaseDao;
import com.dormitory123.millet.dao.UserDao;
import com.dormitory123.millet.pojo.User;


/**
 * @author yanhuanzhan
 * @date 2021/12/26 - 18:01
 */
public class UserDaoImpl  extends BaseDao implements UserDao {
    @Override
    public User queryUserByUserName(String userName) {
        String sql = "SELECT id,username,password,phone,email FROM t_user WHERE username=?";
        return queryForOne(User.class, sql, userName);
    }

    @Override
    public User queryUserByUserNameAndPassword(String userName, String password) {
        String sql = "SELECT id,username,password,phone,email FROM t_user WHERE username=? AND password=?";
        return queryForOne(User.class,sql,userName, password);
    }

    @Override
    public int saveUser(User user) {
        String sql = "INSERT INTO t_user(username,password,phone,email) VALUES(?,?,?,?)";
        return update(sql, user.getUsername(), user.getPassword(), user.getPhone(),user.getEmail());
    }
}
